package com.kymatrix.kycarbon.xsmd.kbpm.server.model.enums;

import cn.hutool.core.convert.Convert;
import com.kymatrix.kycarbon.xsmd.common.business.common.BaseBusinessEnum;
import java.util.Arrays;

import static com.kymatrix.kycarbon.xsmd.common.business.common.BaseBusinessEnum.SysConfigGroupName.WF_PROCESS_TASK_TYPE;

/**
 *
 * 流程任务类型
 */
public enum ProcessTaskTypeEnum implements BaseBusinessEnum {
    MAJOR("0","主办"),
    SECONDARY("1", "协办"),
    RECORD("2","记录"),
    ;
    private final String code;

    private final String name;


    ProcessTaskTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    @Override
    public String getSysConfigGroupName() {
        return WF_PROCESS_TASK_TYPE;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    /**
     * code转成枚举
     * @param code
     * @return
     */
    public static ProcessTaskTypeEnum codeOf(Object code) {
        return Arrays.stream(ProcessTaskTypeEnum.class.getEnumConstants()).filter(e ->
                e.getCode().equals(Convert.toInt(code))
                        || e.name().equalsIgnoreCase(Convert.toStr(code))
                        || e.getName().equalsIgnoreCase(Convert.toStr(code))
        ).findAny().orElse(ProcessTaskTypeEnum.MAJOR);
    }
}
